package org.wu.framework.inner.lazy.orm.spring.config;


import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;
import org.wu.framework.inner.lazy.orm.spring.aop.LazyMasterDynamicPointcutAdvisor;

/**
 * 注入动态数据源切换 切面
 *
 * @author : Jia wei Wu
 * @version 1.0
 * @date : 2021/7/4 6:07 下午
 */
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConditionalOnProperty(prefix = "spring.datasource", value = "url")
public class SpringLazyMasterDynamicBeanAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public LazyMasterDynamicPointcutAdvisor lazyMasterDynamicPointcutAdvisor() {
        LazyMasterDynamicPointcutAdvisor.LazyClearOtherDBInterceptor lazyClearOtherDBInterceptor
                = new LazyMasterDynamicPointcutAdvisor.LazyClearOtherDBInterceptor();
        return new LazyMasterDynamicPointcutAdvisor(lazyClearOtherDBInterceptor);
    }
}
